import { app, BrowserWindow } from 'electron'
import { electronApp, optimizer } from '@electron-toolkit/utils'
import * as mainWin from './mainWin.js';
import { initTray } from './tray.js'
import { readConfig, writeConfig, } from './utils.js'
import { addIpcMain } from './ipcMain.js'
async function createWindow() {
  mainWin.openMainWin();
  if (readConfig() == null) {
    writeConfig({
      mode: {
        label: 'normal',
        url: '/menu'
      }
    })
  }
}
app.whenReady().then(() => {
  electronApp.setAppUserModelId('com.electron')

  app.on('browser-window-created', (_, window) => {
    optimizer.watchWindowShortcuts(window)
  })
  addIpcMain()
  createWindow()
  initTray()

  app.on('activate', function () {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })

})

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.exit()
  }
})

// In this file you can include the rest of your app"s specific main process
// code. You can also put them in separate files and require them here.
